class Solution:
    def totalSteps(self, nums):
        max_time = 0
        stack = [(nums[0], 0)]
        n = len(nums)
        for i in range(1, n):
            max_count = 0
            if nums[i] < stack[-1][0]:
                max_count = 1
            else:
                while stack and nums[i] >= stack[-1][0]:
                    node = stack.pop()
                    max_count = max(max_count, node[1])
                if stack:
                    max_count += 1
            stack.append((nums[i], max_count))
            max_time = max(max_time, max_count)
        return max_time


data = Solution()
nums = [5, 3, 4, 4, 7, 3, 6, 11, 8, 5, 11]
print(data.totalSteps(nums))
